package org.ax.service.plan.imple;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.inject.internal.cglib.proxy.$Dispatcher;
import org.ax.mapper.plan.OrderMapper;
import org.ax.pojo.plan.Order;
import org.ax.service.plan.CustomService;
import org.ax.service.plan.OrderService;
import org.ax.service.plan.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-25-14:41
 */
@Service
public class IOrderService extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    CustomService customService;
    @Autowired
    ProductService productService;
    @Override
    public Page<Order> searchOrders(Page page,String status) {
        QueryWrapper<Order> wrapper=new QueryWrapper<Order>();
        wrapper.eq(!StringUtils.isBlank(status), "status",status);
        Page page1 = getBaseMapper().selectPage(page, wrapper);
        List<Order> orderList = (List<Order>)page1.getRecords();
        for (Order order : orderList) {
            order.setCustom(customService.toCustomId(order.getCustomId()));
            order.setProduct(productService.toProductId(order.getProductId()));
        }
        page1.setRecords(orderList);
        return page1;
    }

    @Override
    public List<Order> findOrderList() {
        return getBaseMapper().selectList(null);
    }

    @Override
    public boolean addOrder(Order order) {
        return getBaseMapper().insert(order)>0;
    }

    @Override
    public boolean updateOrder(Order order) {
        return getBaseMapper().updateById(order)>0;
    }

    @Override
    public boolean deletesCustom(String[] ids) {
        return getBaseMapper().deleteBatchIds(Arrays.asList(ids))>0;
    }
}
